home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / emacs-19.000 / emacs-19 / usr / local / info / emacs-17 < prev    next >
Encoding:
GNU Info File  |  1995-09-11  |  46.1 KB  |  1,112 lines

  1. This is Info file ../info/emacs, produced by Makeinfo-1.55 from the
  2. input file emacs.texi.
  3.  
  4. 
  5. File: emacs,  Node: Shell Mode,  Next: Shell History,  Prev: Interactive Shell,  Up: Shell
  6.  
  7. Shell Mode
  8. ----------
  9.  
  10.    Shell buffer use Shell mode, which defines several special keys
  11. attached to the `C-c' prefix.  They are chosen to resemble the usual
  12. editing and job control characters present in shells that are not under
  13. Emacs, except that you must type `C-c' first.  Here is a complete list
  14. of the special key bindings of Shell mode:
  15.  
  16. `RET'
  17.      At end of buffer send line as input; otherwise, copy current line
  18.      to end of buffer and send it (`comint-send-input').  When a line is
  19.      copied, any text at the beginning of the line that matches the
  20.      variable `shell-prompt-pattern' is left out; this variable's value
  21.      should be a regexp string that matches the prompts that your shell
  22.      uses.
  23.  
  24. `TAB'
  25.      Complete the command name or file name before point in the shell
  26.      buffer (`comint-dynamic-complete').  TAB also completes history
  27.      references (*note History References::.) and environment variable
  28.      names.
  29.  
  30.      The variable `shell-completion-fignore' specifies a list of file
  31.      name extensions to ignore in Shell mode completion.  The default
  32.      setting ignores file names ending in `~', `#' or `%'.  Other
  33.      related Comint modes use the variable `comint-completion-fignore'
  34.      instead.
  35.  
  36. `M-?'
  37.      Display temporarily a list of the possible completions of the file
  38.      name before point in the shell buffer
  39.      (`comint-dynamic-list-filename-completions').
  40.  
  41. `C-d'
  42.      Either delete a character or send EOF
  43.      (`comint-delchar-or-maybe-eof').  Typed at the end of the shell
  44.      buffer, `C-d' sends EOF to the subshell.  Typed at any other
  45.      position in the buffer, `C-d' deletes a character as usual.
  46.  
  47. `C-c C-a'
  48.      Move to the beginning of the line, but after the prompt if any
  49.      (`comint-bol').
  50.  
  51. `C-c C-u'
  52.      Kill all text pending at end of buffer to be sent as input
  53.      (`comint-kill-input').
  54.  
  55. `C-c C-w'
  56.      Kill a word before point (`backward-kill-word').
  57.  
  58. `C-c C-c'
  59.      Interrupt the shell or its current subjob if any
  60.      (`comint-interrupt-subjob').
  61.  
  62. `C-c C-z'
  63.      Stop the shell or its current subjob if any (`comint-stop-subjob').
  64.  
  65. `C-c C-\'
  66.      Send quit signal to the shell or its current subjob if any
  67.      (`comint-quit-subjob').
  68.  
  69. `C-c C-o'
  70.      Kill the last batch of output from a shell command
  71.      (`comint-kill-output').  This is useful if a shell command spews
  72.      out lots of output that just gets in the way.
  73.  
  74. `C-c C-r'
  75. `C-M-l'
  76.      Scroll to display the beginning of the last batch of output at the
  77.      top of the window; also move the cursor there
  78.      (`comint-show-output').
  79.  
  80. `C-c C-e'
  81.      Scroll to put the end of the buffer at the bottom of the window
  82.      (`comint-show-maximum-output').
  83.  
  84. `C-c C-f'
  85.      Move forward across one shell command, but not beyond the current
  86.      line (`shell-forward-command').  The variable
  87.      `shell-command-regexp' specifies how to recognize the end of a
  88.      command.
  89.  
  90. `C-c C-b'
  91.      Move backward across one shell command, but not beyond the current
  92.      line (`shell-backward-command').
  93.  
  94. `C-c C-l'
  95.      Display the buffer's history of shell commands in another window
  96.      (`comint-dynamic-list-input-ring').
  97.  
  98. `M-x dirs'
  99.      Ask the shell what its current directory is, so that Emacs can
  100.      agree with the shell.
  101.  
  102. `M-x send-invisible RET TEXT RET'
  103.      Send TEXT as input to the shell, after reading it without echoing.
  104.      This is useful when a shell command runs a program that asks for
  105.      a password.
  106.  
  107.      Alternatively, you can arrange for Emacs to notice password prompts
  108.      and turn off echoing for them, as follows:
  109.  
  110.           (add-hook `comint-output-filter-functions
  111.                     `comint-watch-for-password-prompt)
  112.  
  113. `M-x comint-continue-subjob'
  114.      Continue the shell process.  This is useful if you accidentally
  115.      suspend the shell process.(1)
  116.  
  117. `M-x comint-strip-ctrl-m'
  118.      Discard all control-m characters from the shell output.  The most
  119.      convenient way to use this command is to make it run automatically
  120.      when you get output from the subshell.  To do that, evaluate this
  121.      Lisp expression:
  122.  
  123.           (add-hook 'comint-output-filter-functions
  124.                     'comint-strip-ctrl-m)
  125.  
  126. `M-x comint-truncate-buffer'
  127.      This command truncates the shell buffer to a certain maximum
  128.      number of lines, specified by the variable
  129.      `comint-buffer-maximum-size'.  Here's how to do this automatically
  130.      each time you get output from the subshell:
  131.  
  132.           (add-hook 'comint-output-filter-functions
  133.                     'comint-truncate-buffer)
  134.  
  135.    Shell mode also customizes the paragraph commands so that only shell
  136. prompts start new paragraphs.  Thus, a paragraph consists of an input
  137. command plus the output that follows it in the buffer.
  138.  
  139.    Shell mode is a derivative of Comint mode, a general purpose mode for
  140. communicating with interactive subprocesses.  Most of the features of
  141. Shell mode actually come from Comint mode, as you can see from the
  142. command names listed above.  The specialization of Shell mode in
  143. particular include the choice of regular expression for detecting
  144. prompts, the directory tracking feature, and a few user commands.
  145.  
  146.    Other Emacs features that use variants of Comint mode include GUD
  147. (*note Debuggers::.) and `M-x run-lisp' (*note External Lisp::.).
  148.  
  149.    You can use `M-x comint-run' to execute any program of your choice
  150. in a subprocess using unmodified Comint mode--without the
  151. specializations of Shell mode.
  152.  
  153.    ---------- Footnotes ----------
  154.  
  155.    (1)  You should not suspend the shell process.  Suspending a subjob
  156. of the shell is a completely different matter--that is normal practice,
  157. but you must use the shell to continue the subjob; this command won't
  158. do it.
  159.  
  160. 
  161. File: emacs,  Node: Shell History,  Next: Shell Options,  Prev: Shell Mode,  Up: Shell
  162.  
  163. Shell Command History
  164. ---------------------
  165.  
  166.    Shell buffers support three ways of repeating earlier commands.  You
  167. can use the same keys used in the minibuffer; these work much as they do
  168. in the minibuffer, inserting text from prior commands while point
  169. remains always at the end of the buffer.  You can move through the
  170. buffer to previous inputs in their original place, then resubmit them or
  171. copy them to the end.  Or you can use a `!'-style history reference.
  172.  
  173. * Menu:
  174.  
  175. * Ring: Shell Ring.             Fetching commands from the history list.
  176. * Copy: Shell History Copying.  Moving to a command and then copying it.
  177. * History References::          Expanding `!'-style history references.
  178.  
  179. 
  180. File: emacs,  Node: Shell Ring,  Next: Shell History Copying,  Up: Shell History
  181.  
  182. Shell History Ring
  183. ..................
  184.  
  185. `M-p'
  186.      Fetch the next earlier old shell command.
  187.  
  188. `M-n'
  189.      Fetch the next later old shell command.
  190.  
  191. `M-r REGEXP RET'
  192. `M-s REGEXP RET'
  193.      Search backwards or forwards for old shell commands that match
  194.      REGEXP.
  195.  
  196.    Shell buffers provide a history of previously entered shell
  197. commands.  To reuse shell commands from the history, use the editing
  198. commands `M-p', `M-n', `M-r' and `M-s'.  These work just like the
  199. minibuffer history commands except that they operate on the text at the
  200. end of the shell buffer, where you would normally insert text to send
  201. to the shell.
  202.  
  203.    `M-p' fetches an earlier shell command to the end of the shell
  204. buffer.  Successive use of `M-p' fetches successively earlier shell
  205. commands, each replacing any text that was already present as potential
  206. shell input.  `M-n' does likewise except that it finds successively
  207. more recent shell commands from the buffer.
  208.  
  209.    The history search commands `M-r' and `M-s' read a regular
  210. expression and search through the history for a matching command.  Aside
  211. from the choice of which command to fetch, they work just like `M-p'
  212. and `M-r'.  If you enter an empty regexp, these commands reuse the same
  213. regexp used last time.
  214.  
  215.    When you find the previous input you want, you can resubmit it by
  216. typing RET, or you can edit it first and then resubmit it if you wish.
  217.  
  218.    These commands get the text of previous shell commands from a special
  219. history list, not from the shell buffer itself.  Thus, editing the shell
  220. buffer, or even killing large parts of it, does not affect the history
  221. that these commands access.
  222.  
  223.    Some shells store their command histories in files so that you can
  224. refer to previous commands from previous shell sessions.  Emacs reads
  225. the command history file for your chosen shell, to initialize its own
  226. command history.  The file name is `~/.bash_history' for bash,
  227. `~/.sh_history' for ksh, and `~/.history' for other shells.
  228.  
  229. 
  230. File: emacs,  Node: Shell History Copying,  Next: History References,  Prev: Shell Ring,  Up: Shell History
  231.  
  232. Shell History Copying
  233. .....................
  234.  
  235. `C-c C-p'
  236.      Move point to the previous prompt (`comint-previous-prompt').
  237.  
  238. `C-c C-n'
  239.      Move point to the following prompt (`comint-next-prompt').
  240.  
  241. `C-c RET'
  242.      Copy the input command which point is in, inserting the copy at
  243.      the end of the buffer (`comint-copy-old-input').  This is useful
  244.      if you move point back to a previous command.  After you copy the
  245.      command, you can submit the copy as input with RET.  If you wish,
  246.      you can edit the copy before resubmitting it.
  247.  
  248.    Moving to a previous input and then copying it with `C-c RET'
  249. produces the same results--the same buffer contents--that you would get
  250. by using `M-p' enough times to fetch that previous input from the
  251. history list.  However, `C-c RET' copies the text from the buffer,
  252. which can be different from what is in the history list if you edit the
  253. input text in the buffer after it has been sent.
  254.  
  255. 
  256. File: emacs,  Node: History References,  Prev: Shell History Copying,  Up: Shell History
  257.  
  258. Shell History References
  259. ........................
  260.  
  261.    Various shells including csh and bash support "history references"
  262. that begin with `!' and `^'.  Shell mode can understands these
  263. constructs and perform the history substitution for you.  If you insert
  264. a history reference and type TAB, this searches the input history for a
  265. matching command, performs substitution if necessary, and places the
  266. result in the buffer in place of the history reference.  For example,
  267. you can fetch the most recent command beginning with `mv' with `! m v
  268. TAB'.  You can edit the command if you wish, and then resubmit the
  269. command to the shell by typing RET.
  270.  
  271.    History references take effect only following a shell prompt.  The
  272. variable `shell-prompt-pattern' specifies how to recognize a shell
  273. prompt.  Comint modes in general use the variable
  274. `comint-prompt-regexp' to specify how to find a prompt; Shell mode uses
  275. `shell-prompt-pattern' to set up the local value of
  276. `comint-prompt-regexp'.
  277.  
  278.    Shell mode can optionally expand history references in the buffer
  279. when you send them to the shell.  To request this, set the variable
  280. `comint-input-autoexpand' to `input'.
  281.  
  282.    You can make SPC perform history expansion by binding SPC to the
  283. command `comint-magic-space'.
  284.  
  285. 
  286. File: emacs,  Node: Shell Options,  Next: Remote Host,  Prev: Shell History,  Up: Shell
  287.  
  288. Shell Mode Options
  289. ------------------
  290.  
  291.    If the variable `comint-scroll-to-bottom-on-input' is non-`nil',
  292. insertion and yank commands scroll the selected window to the bottom
  293. before inserting.
  294.  
  295.    If `comint-scroll-show-maximum-output' is non-`nil' (which is the
  296. default), then scrolling due to arrival of output tries to place the
  297. last line of text at the bottom line of the window, so as to show as
  298. much useful text as possible.  (This mimics the scrolling behavior of
  299. many terminals.)
  300.  
  301.    By setting `comint-scroll-to-bottom-on-output', you can opt for
  302. having point jump to the end of the buffer whenever output arrives--no
  303. matter where in the buffer point was before.  If the value is `this',
  304. point jumps in the selected window.  If the value is `all', point jumps
  305. in each window that shows the comint buffer.  If the value is `other',
  306. point jumps in all nonselected windows that show the current buffer.
  307. The default value is `nil', which means point does not jump to the end.
  308.  
  309.    The variable `comint-input-ignoredups' controls whether successive
  310. identical inputs are stored in the input history.  A non-`nil' value
  311. means to omit an input that is the same as the previous input.  The
  312. default is `nil', which means to store each input even if it is equal
  313. to the previous input.
  314.  
  315.    Three variables customize file name completion.  The variable
  316. `comint-completion-addsuffix' controls whether completion inserts a
  317. space or a slash to indicate a fully completed file or directory name
  318. (non-`nil' means do insert a space or slash).
  319. `comint-completion-recexact', if non-`nil', directs TAB to choose the
  320. shortest possible completion if the usual Emacs completion algorithm
  321. cannot add even a single character.  `comint-completion-autolist', if
  322. non-`nil', says to list all the possible completions whenever
  323. completion is not exact.
  324.  
  325.    The command `comint-dynamic-complete-variable' does variable name
  326. completion using the environment variables as set within Emacs.  The
  327. variables controlling file name completion apply to variable name
  328. completion too.  This command is normally available through the menu
  329. bar.
  330.  
  331.    Command completion normally considers only executable files.  If you
  332. set `shell-command-execonly' to `nil', it considers nonexecutable files
  333. as well.
  334.  
  335.    You can configure the behavior of `pushd'.  Variables control
  336. whether `pushd' behaves like `cd' if no argument is given
  337. (`shell-pushd-tohome'), pop rather than rotate with a numeric argument
  338. (`shell-pushd-dextract'), and only add directories to the directory
  339. stack if they are not already on it (`shell-pushd-dunique').  The
  340. values you choose should match the underlying shell, of course.
  341.  
  342. 
  343. File: emacs,  Node: Remote Host,  Prev: Shell Options,  Up: Shell
  344.  
  345. Remote Host Shell
  346. -----------------
  347.  
  348.    Emacs provides two commands for logging in to another computer and
  349. communicating with it through an Emacs buffer.
  350.  
  351. `M-x telnet RET HOSTNAME RET'
  352.      Set up a Telnet connection to the computer named HOSTNAME.
  353.  
  354. `M-x rlogin RET HOSTNAME RET'
  355.      Set up an Rlogin connection to the computer named HOSTNAME.
  356.  
  357.    Use `M-x telnet' to set up a Telnet connection to another computer.
  358. (Telnet is the standard Internet protocol for remote login.) It reads
  359. the host name of the other computer as an argument with the minibuffer.
  360. Once the connection is established, talking to the other computer
  361. works like talking to a subshell: you can edit input with the usual
  362. Emacs commands, and send it a line at a time by typing RET.  The output
  363. is inserted in the Telnet buffer interspersed with the input.
  364.  
  365.    Use `M-x rlogin' to set up an Rlogin connection.  Rlogin is another
  366. remote login communication protocol, essentially much like the Telnet
  367. protocol but incompatible with it, and supported only by certain
  368. systems.  Rlogin's advantages are that you can arrange not to have to
  369. give your user name and password when communicating between two machines
  370. you frequently use, and that you can make an 8-bit-clean connection.
  371. (To do that in Emacs, set `rlogin-explicit-args' to `("-8")' before you
  372. run Rlogin.)
  373.  
  374.    `M-x rlogin' sets up the default file directory of the Emacs buffer
  375. to access the remote host via FTP (*note File Names::.), and it tracks
  376. the shell commands that change the current directory just like Shell
  377. mode.
  378.  
  379. 
  380. File: emacs,  Node: Emacs Server,  Next: Hardcopy,  Prev: Shell,  Up: Top
  381.  
  382. Using Emacs as a Server
  383. =======================
  384.  
  385.    Various programs such as `mail' can invoke your choice of editor to
  386. edit a particular piece of text, such as a message that you are
  387. sending.  By convention, most of these programs use the environment
  388. variable `EDITOR' to specify which editor to run.  If you set `EDITOR'
  389. to `emacs', they invoke Emacs--but in an inconvenient fashion, by
  390. starting a new, separate Emacs process.  This is inconvenient because
  391. it takes time and because the new Emacs process doesn't share the
  392. buffers in the existing Emacs process.
  393.  
  394.    You can arrange to use your existing Emacs process as the editor for
  395. programs like `mail' by using the Emacs client and Emacs server
  396. programs.  Here is how.
  397.  
  398.    First, the preparation.  Within Emacs, call the function
  399. `server-start'.  (Your `.emacs' file can do this automatically if you
  400. add the expression `(server-start)' to it.)  Then, outside Emacs, set
  401. the `EDITOR' environment variable to `emacsclient'.  (Note that some
  402. programs use a different environment variable; for example, to make TeX
  403. use `emacsclient', you should set the `TEXEDIT' environment variable to
  404. `emacsclient +%d %s'.)
  405.  
  406.    Then, whenever any program invokes your specified `EDITOR' program,
  407. the effect is to send a message to your principal Emacs telling it to
  408. visit a file.  (That's what the program `emacsclient' does.) Emacs
  409. displays the buffer immediately and you can immediately begin editing
  410. it.
  411.  
  412.    When you've finished editing that buffer, type `C-x #'
  413. (`server-edit').  This saves the file and sends a message back to the
  414. `emacsclient' program telling it to exit.  The programs that use
  415. `EDITOR' wait for the "editor" (actually, `emacsclient') to exit.  `C-x
  416. #' also checks for other pending external requests to edit various
  417. files, and selects the next such file.
  418.  
  419.    You can switch to a server buffer manually if you wish; you don't
  420. have to arrive at it with `C-x #'.  But `C-x #' is the only way to say
  421. that you are "finished" with one.
  422.  
  423.    If you set the variable `server-window' to a window or a frame, `C-x
  424. #' displays the server buffer in that window or in that frame.
  425.  
  426.    While `mail' or another application is waiting for `emacsclient' to
  427. finish, `emacsclient' does not read terminal input.  So the terminal
  428. that `mail' was using is effectively blocked for the duration.  In
  429. order to edit with your principal Emacs, you need to be able to use it
  430. without using that terminal.  There are two ways to do this:
  431.  
  432.    * Using a window system, run `mail' and the principal Emacs in two
  433.      separate windows.  While `mail' is waiting for `emacsclient', the
  434.      window where it was running is blocked, but you can use Emacs by
  435.      switching windows.
  436.  
  437.    * Use Shell mode in Emacs to run the other program such as `mail';
  438.      then, `emacsclient' blocks only the subshell under Emacs, and you
  439.      can still use Emacs to edit the file.
  440.  
  441.    Some programs write temporary files for you to edit.  After you edit
  442. the temporary file, the program reads it back and deletes it.  If the
  443. Emacs server is later asked to edit the same file name, it should assume
  444. this has nothing to do with the previous occasion for that file name.
  445. The server accomplishes this by killing the temporary file's buffer when
  446. you finish with the file.  Use the variable `server-temp-file-regexp'
  447. to specify which files are temporary in this sense; its value should be
  448. a regular expression that matches file names that are temporary.
  449.  
  450. 
  451. File: emacs,  Node: Hardcopy,  Next: Postscript,  Prev: Emacs Server,  Up: Top
  452.  
  453. Hardcopy Output
  454. ===============
  455.  
  456.    The Emacs commands for making hardcopy let you print either an entire
  457. buffer or just part of one, either with or without page headers.  See
  458. also the hardcopy commands of Dired (*note Misc File Ops::.) and the
  459. diary (*note Diary Commands::.).
  460.  
  461. `M-x print-buffer'
  462.      Print hardcopy of current buffer with page headings containing the
  463.      file name and page number.
  464.  
  465. `M-x lpr-buffer'
  466.      Print hardcopy of current buffer without page headings.  makes no
  467.      page headings.
  468.  
  469. `M-x print-region'
  470.      Like `print-buffer' but print only the current region.
  471.  
  472. `M-x lpr-region'
  473.      Like `lpr-buffer' but print only the current region.
  474.  
  475.    The hardcopy commands (aside from the Postscript commands) pass extra
  476. switches to the `lpr' program based on the value of the variable
  477. `lpr-switches'.  Its value should be a list of strings, each string an
  478. option starting with `-'.  For example, to use a printer named
  479. `nearme', set `lpr-switches' like this:
  480.  
  481.      (setq lpr-switches '("-Pnearme"))
  482.  
  483.    The variable `lpr-header-switches' similarly specifies the extra
  484. switches to use to make page headers.
  485.  
  486. 
  487. File: emacs,  Node: Postscript,  Next: Sorting,  Prev: Hardcopy,  Up: Top
  488.  
  489. Postscript Hardcopy
  490. ===================
  491.  
  492.    These commands convert buffer contents to Postscript, either
  493. printing it or leaving it in another Emacs buffer.
  494.  
  495. `M-x ps-print-buffer'
  496.      Print hardcopy of the current buffer in Postscript form.
  497.  
  498. `M-x ps-print-region'
  499.      Print hardcopy of the current region in Postscript form.
  500.  
  501. `M-x ps-print-buffer-with-faces'
  502.      Print hardcopy of the current buffer in Postscript form, showing
  503.      the faces used in the text by means of Postscript features.
  504.  
  505. `M-x ps-print-region-with-faces'
  506.      Print hardcopy of the current region in Postscript form, showing
  507.      the faces used in the text.
  508.  
  509. `M-x ps-spool-buffer'
  510.      Generate Postscript for the current buffer text.
  511.  
  512. `M-x ps-spool-region'
  513.      Generate Postscript for the current region.
  514.  
  515. `M-x ps-spool-buffer-with-faces'
  516.      Generate Postscript for the current buffer, showing the faces used.
  517.  
  518. `M-x ps-spool-region-with-faces'
  519.      Generate Postscript for the current region, showing the faces used.
  520.  
  521.    The Postscript commands, `ps-print-buffer' and `ps-print-region',
  522. print buffer contents in Postscript form.  One command prints the
  523. entire buffer; the other, just the region.  The corresponding
  524. `-with-faces' commands, `ps-print-buffer-with-faces' and
  525. `ps-print-region-with-faces', use Postscript features to show the faces
  526. (fonts and colors) in the text properties of the text being printed.
  527.  
  528.    All four of the commands above use the variables `ps-lpr-command'
  529. and `ps-lpr-switches' to specify how to print the output.
  530. `ps-lpr-command' specifies the command name to run, and
  531. `ps-lpr-switches' specifies command line options to use.  If you don't
  532. set these variables yourself, they take their initial values from
  533. `lpr-command' and `lpr-switches'.
  534.  
  535.    The variable `ps-print-header' controls whether these commands add
  536. header lines to each page--set it to `nil' to turn headers off.  You
  537. can turn off color processing by setting `ps-print-color-p' to `nil'.
  538. Many other customization variables for these commands are defined and
  539. described in the Lisp file `ps-print.el'.
  540.  
  541.    The commands whose names have `spool' instead of `print' generate
  542. the Postscript output in an Emacs buffer instead of sending it to the
  543. printer.
  544.  
  545. 
  546. File: emacs,  Node: Sorting,  Next: Narrowing,  Prev: Postscript,  Up: Top
  547.  
  548. Sorting Text
  549. ============
  550.  
  551.    Emacs provides several commands for sorting text in the buffer.  All
  552. operate on the contents of the region (the text between point and the
  553. mark).  They divide the text of the region into many "sort records",
  554. identify a "sort key" for each record, and then reorder the records
  555. into the order determined by the sort keys.  The records are ordered so
  556. that their keys are in alphabetical order, or, for numeric sorting, in
  557. numeric order.  In alphabetic sorting, all upper case letters `A'
  558. through `Z' come before lower case `a', in accord with the ASCII
  559. character sequence.
  560.  
  561.    The various sort commands differ in how they divide the text into
  562. sort records and in which part of each record is used as the sort key.
  563. Most of the commands make each line a separate sort record, but some
  564. commands use paragraphs or pages as sort records.  Most of the sort
  565. commands use each entire sort record as its own sort key, but some use
  566. only a portion of the record as the sort key.
  567.  
  568. `M-x sort-lines'
  569.      Divide the region into lines, and sort by comparing the entire
  570.      text of a line.  A numeric argument means sort into descending
  571.      order.
  572.  
  573. `M-x sort-paragraphs'
  574.      Divide the region into paragraphs, and sort by comparing the entire
  575.      text of a paragraph (except for leading blank lines).  A numeric
  576.      argument means sort into descending order.
  577.  
  578. `M-x sort-pages'
  579.      Divide the region into pages, and sort by comparing the entire
  580.      text of a page (except for leading blank lines).  A numeric
  581.      argument means sort into descending order.
  582.  
  583. `M-x sort-fields'
  584.      Divide the region into lines, and sort by comparing the contents of
  585.      one field in each line.  Fields are defined as separated by
  586.      whitespace, so the first run of consecutive non-whitespace
  587.      characters in a line constitutes field 1, the second such run
  588.      constitutes field 2, etc.
  589.  
  590.      Specify which field to sort by with a numeric argument: 1 to sort
  591.      by field 1, etc.  A negative argument means count fields from the
  592.      right instead of from the left; thus, minus 1 means sort by the
  593.      last field.  If several lines have identical contents in the field
  594.      being sorted, they keep same relative order that they had in the
  595.      original buffer.
  596.  
  597.      A negative argument means count fields from the right (from the
  598.      end of the line).
  599.  
  600. `M-x sort-numeric-fields'
  601.      Like `M-x sort-fields' except the specified field is converted to
  602.      an integer for each line, and the numbers are compared.  `10'
  603.      comes before `2' when considered as text, but after it when
  604.      considered as a number.
  605.  
  606. `M-x sort-columns'
  607.      Like `M-x sort-fields' except that the text within each line used
  608.      for comparison comes from a fixed range of columns.  See below for
  609.      an explanation.
  610.  
  611. `M-x reverse-region'
  612.      Reverse the order of the lines in the region.  This is useful for
  613.      sorting into descending order by fields or columns, since those
  614.      sort commands do not have a feature for doing that.
  615.  
  616.    For example, if the buffer contains this:
  617.  
  618.      On systems where clash detection (locking of files being edited) is
  619.      implemented, Emacs also checks the first time you modify a buffer
  620.      whether the file has changed on disk since it was last visited or
  621.      saved.  If it has, you are asked to confirm that you want to change
  622.      the buffer.
  623.  
  624. applying `M-x sort-lines' to the entire buffer produces this:
  625.  
  626.      On systems where clash detection (locking of files being edited) is
  627.      implemented, Emacs also checks the first time you modify a buffer
  628.      saved.  If it has, you are asked to confirm that you want to change
  629.      the buffer.
  630.      whether the file has changed on disk since it was last visited or
  631.  
  632. where the upper case `O' sorts before all lower case letters.  If you
  633. use `C-u 2 M-x sort-fields' instead, you get this:
  634.  
  635.      implemented, Emacs also checks the first time you modify a buffer
  636.      saved.  If it has, you are asked to confirm that you want to change
  637.      the buffer.
  638.      On systems where clash detection (locking of files being edited) is
  639.      whether the file has changed on disk since it was last visited or
  640.  
  641. where the sort keys were `Emacs', `If', `buffer', `systems' and `the'.
  642.  
  643.    `M-x sort-columns' requires more explanation.  You specify the
  644. columns by putting point at one of the columns and the mark at the other
  645. column.  Because this means you cannot put point or the mark at the
  646. beginning of the first line to sort, this command uses an unusual
  647. definition of `region': all of the line point is in is considered part
  648. of the region, and so is all of the line the mark is in, as well as all
  649. the lines in between.
  650.  
  651.    For example, to sort a table by information found in columns 10 to
  652. 15, you could put the mark on column 10 in the first line of the table,
  653. and point on column 15 in the last line of the table, and then run
  654. `sort-columns'.  Equivalently, you could run it with the mark on column
  655. 15 in the first line and point on column 10 in the last line.
  656.  
  657.    This can be thought of as sorting the rectangle specified by point
  658. and the mark, except that the text on each line to the left or right of
  659. the rectangle moves along with the text inside the rectangle.  *Note
  660. Rectangles::.
  661.  
  662.    Many of the sort commands ignore case differences when comparing, if
  663. `sort-fold-case' is non-`nil'.
  664.  
  665. 
  666. File: emacs,  Node: Narrowing,  Next: Two-Column,  Prev: Sorting,  Up: Top
  667.  
  668. Narrowing
  669. =========
  670.  
  671.    "Narrowing" means focusing in on some portion of the buffer, making
  672. the rest temporarily inaccessible.  The portion which you can still get
  673. to is called the "accessible portion".  Canceling the narrowing, which
  674. makes the entire buffer once again accessible, is called "widening".
  675. The amount of narrowing in effect in a buffer at any time is called the
  676. buffer's "restriction".
  677.  
  678.    Narrowing can make it easier to concentrate on a single subroutine or
  679. paragraph by eliminating clutter.  It can also be used to restrict the
  680. range of operation of a replace command or repeating keyboard macro.
  681.  
  682. `C-x n n'
  683.      Narrow down to between point and mark (`narrow-to-region').
  684.  
  685. `C-x n w'
  686.      Widen to make the entire buffer accessible again (`widen').
  687.  
  688. `C-x n p'
  689.      Narrow down to the current page (`narrow-to-page').
  690.  
  691.    When you have narrowed down to a part of the buffer, that part
  692. appears to be all there is.  You can't see the rest, you can't move
  693. into it (motion commands won't go outside the accessible part), you
  694. can't change it in any way.  However, it is not gone, and if you save
  695. the file all the inaccessible text will be saved.  The word `Narrow'
  696. appears in the mode line whenever narrowing is in effect.
  697.  
  698.    The primary narrowing command is `C-x n n' (`narrow-to-region').  It
  699. sets the current buffer's restrictions so that the text in the current
  700. region remains accessible but all text before the region or after the
  701. region is inaccessible.  Point and mark do not change.
  702.  
  703.    Alternatively, use `C-x n p' (`narrow-to-page') to narrow down to
  704. the current page.  *Note Pages::, for the definition of a page.
  705.  
  706.    The way to cancel narrowing is to widen with `C-x n w' (`widen').
  707. This makes all text in the buffer accessible again.
  708.  
  709.    You can get information on what part of the buffer you are narrowed
  710. down to using the `C-x =' command.  *Note Position Info::.
  711.  
  712.    Because narrowing can easily confuse users who do not understand it,
  713. `narrow-to-region' is normally a disabled command.  Attempting to use
  714. this command asks for confirmation and gives you the option of enabling
  715. it; if you enable the command, confirmation will no longer be required
  716. for it.  *Note Disabling::.
  717.  
  718. 
  719. File: emacs,  Node: Two-Column,  Next: Editing Binary Files,  Prev: Narrowing,  Up: Top
  720.  
  721. Two-Column Editing
  722. ==================
  723.  
  724.    Two-column mode lets you conveniently edit two side-by-side columns
  725. of text.  It uses two side-by-side windows, each showing its own buffer.
  726.  
  727.    There are three ways to enter two-column mode:
  728.  
  729. `C-x 6 2'
  730.      Enter two-column mode with the current buffer on the left, and on
  731.      the right, a buffer whose name is based on the current buffer's
  732.      name (`tc-two-columns').  If the right-hand buffer doesn't already
  733.      exist, it starts out empty; the current buffer's contents are not
  734.      changed.
  735.  
  736.      This command is appropriate when the current buffer contains just
  737.      one column and you want to add another column.
  738.  
  739. `C-x 6 s'
  740.      Split the current buffer, which contains two-column text, into two
  741.      buffers, and display them side by side (`tc-split').  The current
  742.      buffer becomes the left-hand buffer, but the text in the right-hand
  743.      column is moved into the right-hand buffer.  The current column
  744.      specifies the split point.  Splitting starts with the current line
  745.      and continues to the end of the buffer.
  746.  
  747.      This command is appropriate when you have a buffer that already
  748.      contains two-column text, and you wish to separate the columns
  749.      temporarily.
  750.  
  751. `C-x 6 b BUFFER RET'
  752.      Enter two-column mode using the current buffer as the left-hand
  753.      buffer, and using buffer BUFFER as the right-hand buffer
  754.      (`tc-associate-buffer').
  755.  
  756.    `C-x 6 s' looks for a column separator which is a string that
  757. appears on each line between the two columns.  You can specify the width
  758. of the separator with a numeric argument to `C-x 6 s'; that many
  759. characters, before point, constitute the separator string.  By default,
  760. the width is 1, so the column separator is the character before point.
  761.  
  762.    When a line has the separator at the proper place, `C-x 6 s' puts
  763. the text after the separator into the right-hand buffer, and deletes the
  764. separator.  Lines that don't have the column separator at the proper
  765. place remain unsplit; they stay in the left-hand buffer, and the
  766. right-hand buffer gets an empty line to correspond.  (This is the way
  767. to write a line that spans both columns while in two-column mode: write
  768. it in the left-hand buffer, and put an empty line in the right-hand
  769. buffer.)
  770.  
  771.    It's not a good idea to use ordinary scrolling commands during
  772. two-column editing, because that separates the two parts of each split
  773. line.  Instead, use these special scroll commands:
  774.  
  775. `C-x 6 SPC'
  776.      Scroll both buffers up, in lock step (`tc-scroll-up').
  777.  
  778. `C-x 6 DEL'
  779.      Scroll both buffers down, in lock step (`tc-scroll-down').
  780.  
  781. `C-x 6 C-l'
  782.      Recenter both buffers, in lock step (`tc-recenter').
  783.  
  784.    When you have edited both buffers as you wish, merge them with `C-x
  785. 6 1' (`tc-merge').  This copies the text from the right-hand buffer as
  786. a second column in the other buffer.  To go back to two-column editing,
  787. use `C-x 6 s'.
  788.  
  789.    Use `C-x 6 d' to disassociate the two buffers, leaving each as it
  790. stands (`tc-dissociate').  If the other buffer, the one not current
  791. when you type `C-x 6 d', is empty, `C-x 6 d' kills it.
  792.  
  793. 
  794. File: emacs,  Node: Editing Binary Files,  Next: Saving Emacs Sessions,  Prev: Two-Column,  Up: Top
  795.  
  796. Editing Binary Files
  797. ====================
  798.  
  799.    There is a special major mode for editing binary files: Hexl mode.
  800. To use it, use `M-x hexl-find-file' instead of `C-x C-f' to visit the
  801. file.  This command converts the file's contents to hexadecimal and
  802. lets you edit the translation.  When you save the file, it is converted
  803. automatically back to binary.
  804.  
  805.    You can also use `M-x hexl-mode' to translate an existing buffer
  806. into hex.  This is useful if you visit a file normally and then discover
  807. it is a binary file.
  808.  
  809.    Ordinary text characters overwrite in Hexl mode.  This is to reduce
  810. the risk of accidentally spoiling the alignment of data in the file.
  811. There are special commands for insertion.  Here is a list of the
  812. commands of Hexl mode:
  813.  
  814. `C-M-d'
  815.      Insert a byte with a code typed in decimal.
  816.  
  817. `C-M-o'
  818.      Insert a byte with a code typed in octal.
  819.  
  820. `C-M-x'
  821.      Insert a byte with a code typed in hex.
  822.  
  823. `C-x ['
  824.      Move to the beginning of a 1k-byte "page".
  825.  
  826. `C-x ]'
  827.      Move to the end of a 1k-byte "page".
  828.  
  829. `M-g'
  830.      Move to an address specified in hex.
  831.  
  832. `M-j'
  833.      Move to an address specified in decimal.
  834.  
  835. `C-c C-c'
  836.      Leave Hexl mode, going back to the major mode this buffer had
  837.      before you invoked `hexl-mode'.
  838.  
  839. 
  840. File: emacs,  Node: Saving Emacs Sessions,  Next: Recursive Edit,  Prev: Editing Binary Files,  Up: Top
  841.  
  842. Saving Emacs Sessions
  843. =====================
  844.  
  845.    You can use the Desktop library to save the state of Emacs from one
  846. session to another.  Saving the state means that Emacs starts up with
  847. the same set of buffers, major modes, buffer positions, and so on that
  848. the previous Emacs session had.
  849.  
  850.    To use Desktop, you should first add these lines to your `.emacs'
  851. file, preferably at or near the end:
  852.  
  853.      (load "desktop")
  854.      (desktop-load-default)
  855.      (desktop-read)
  856.  
  857. Then, to enable state saving in a particular Emacs session, use the
  858. command `M-x desktop-save'.  Once you have done this, the state of this
  859. Emacs session will be saved when you exit Emacs.
  860.  
  861.    In order for Emacs to recover the state from a previous session, you
  862. must start it with the same current directory as you used when you
  863. started the previous session.
  864.  
  865.    The variable `desktop-files-not-to-save' controls which files are
  866. excluded from state saving.  Its value is a regular expression that
  867. matches the files to exclude.  By default, remote (ftp-accessed) files
  868. are excluded; this is because visiting them again in the subsequent
  869. session would be slow.  If you want to include these files in state
  870. saving, set `desktop-files-not-to-save' to `"^$"'.
  871.  
  872. 
  873. File: emacs,  Node: Recursive Edit,  Next: Emulation,  Prev: Saving Emacs Sessions,  Up: Top
  874.  
  875. Recursive Editing Levels
  876. ========================
  877.  
  878.    A "recursive edit" is a situation in which you are using Emacs
  879. commands to perform arbitrary editing while in the middle of another
  880. Emacs command.  For example, when you type `C-r' inside of a
  881. `query-replace', you enter a recursive edit in which you can change the
  882. current buffer.  On exiting from the recursive edit, you go back to the
  883. `query-replace'.
  884.  
  885.    "Exiting" the recursive edit means returning to the unfinished
  886. command, which continues execution.  The command to exit is `C-M-c'
  887. (`exit-recursive-edit').
  888.  
  889.    You can also "abort" the recursive edit.  This is like exiting, but
  890. also quits the unfinished command immediately.  Use the command `C-]'
  891. (`abort-recursive-edit') to do this.  *Note Quitting::.
  892.  
  893.    The mode line shows you when you are in a recursive edit by
  894. displaying square brackets around the parentheses that always surround
  895. the major and minor mode names.  Every window's mode line shows this,
  896. in the same way, since being in a recursive edit is true of Emacs as a
  897. whole rather than any particular window or buffer.
  898.  
  899.    It is possible to be in recursive edits within recursive edits.  For
  900. example, after typing `C-r' in a `query-replace', you may type a
  901. command that enters the debugger.  This begins a recursive editing level
  902. for the debugger, within the recursive editing level for `C-r'.  Mode
  903. lines display a pair of square brackets for each recursive editing
  904. level currently in progress.
  905.  
  906.    Exiting the inner recursive edit (such as, with the debugger `c'
  907. command) resumes the command running in the next level up.  When that
  908. command finishes, you can then use `C-M-c' to exit another recursive
  909. editing level, and so on.  Exiting applies to the innermost level only.
  910. Aborting also gets out of only one level of recursive edit; it returns
  911. immediately to the command level of the previous recursive edit.  If you
  912. wish, you can then abort the next recursive editing level.
  913.  
  914.    Alternatively, the command `M-x top-level' aborts all levels of
  915. recursive edits, returning immediately to the top level command reader.
  916.  
  917.    The text being edited inside the recursive edit need not be the same
  918. text that you were editing at top level.  It depends on what the
  919. recursive edit is for.  If the command that invokes the recursive edit
  920. selects a different buffer first, that is the buffer you will edit
  921. recursively.  In any case, you can switch buffers within the recursive
  922. edit in the normal manner (as long as the buffer-switching keys have
  923. not been rebound).  You could probably do all the rest of your editing
  924. inside the recursive edit, visiting files and all.  But this could have
  925. surprising effects (such as stack overflow) from time to time.  So
  926. remember to exit or abort the recursive edit when you no longer need it.
  927.  
  928.    In general, we try to minimize the use of recursive editing levels in
  929. GNU Emacs.  This is because they constrain you to "go back" in a
  930. particular order-from the innermost level toward the top level.  When
  931. possible, we present different activities in separate buffers so that
  932. you can switch between them as you please.  Some commands switch to a
  933. new major mode which provides a command to switch back.  These
  934. approaches give you more flexibility to go back to unfinished tasks in
  935. the order you choose.
  936.  
  937. 
  938. File: emacs,  Node: Emulation,  Next: Dissociated Press,  Prev: Recursive Edit,  Up: Top
  939.  
  940. Emulation
  941. =========
  942.  
  943.    GNU Emacs can be programmed to emulate (more or less) most other
  944. editors.  Standard facilities can emulate these:
  945.  
  946. EDT (DEC VMS editor)
  947.      Turn on EDT emulation with `M-x edt-emulation-on'.  `M-x
  948.      edt-emulation-off' restores normal Emacs command bindings.
  949.  
  950.      Most of the EDT emulation commands are keypad keys, and most
  951.      standard Emacs key bindings are still available.  The EDT
  952.      emulation rebindings are done in the global keymap, so there is no
  953.      problem switching buffers or major modes while in EDT emulation.
  954.  
  955. vi (Berkeley editor)
  956.      Viper is the newest emulator for vi.  It implements several levels
  957.      of emulation; level 1 is closest to vi itself, while level 5
  958.      departs somewhat from strict emulation to take advantage of the
  959.      capabilities of Emacs.  To invoke Viper, type `M-x viper-mode'; it
  960.      will guide you the rest of the way and ask for the emulation level.
  961.  
  962. vi (another emulator)
  963.      `M-x vi-mode' enters a major mode that replaces the previously
  964.      established major mode.  All of the vi commands that, in real vi,
  965.      enter "input" mode are programmed instead to return to the
  966.      previous major mode.  Thus, ordinary Emacs serves as vi's "input"
  967.      mode.
  968.  
  969.      Because vi emulation works through major modes, it does not work
  970.      to switch buffers during emulation.  Return to normal Emacs first.
  971.  
  972.      If you plan to use vi emulation much, you probably want to bind a
  973.      key to the `vi-mode' command.
  974.  
  975. vi (alternate emulator)
  976.      `M-x vip-mode' invokes another vi emulator, said to resemble real
  977.      vi more thoroughly than `M-x vi-mode'.  "Input" mode in this
  978.      emulator is changed from ordinary Emacs so you can use ESC to go
  979.      back to emulated vi command mode.  To get from emulated vi command
  980.      mode back to ordinary Emacs, type `C-z'.
  981.  
  982.      This emulation does not work through major modes, and it is
  983.      possible to switch buffers in various ways within the emulator.
  984.      It is not so necessary to assign a key to the command `vip-mode' as
  985.      it is with `vi-mode' because terminating insert mode does not use
  986.      it.
  987.  
  988.      For full information, see the long comment at the beginning of the
  989.      source file, which is `lisp/vip.el' in the Emacs distribution.
  990.  
  991. 
  992. File: emacs,  Node: Dissociated Press,  Next: Amusements,  Prev: Emulation,  Up: Top
  993.  
  994. Dissociated Press
  995. =================
  996.  
  997.    `M-x dissociated-press' is a command for scrambling a file of text
  998. either word by word or character by character.  Starting from a buffer
  999. of straight English, it produces extremely amusing output.  The input
  1000. comes from the current Emacs buffer.  Dissociated Press writes its
  1001. output in a buffer named `*Dissociation*', and redisplays that buffer
  1002. after every couple of lines (approximately) so you can read the output
  1003. as it comes out.
  1004.  
  1005.    Dissociated Press asks every so often whether to continue generating
  1006. output.  Answer `n' to stop it.  You can also stop at any time by
  1007. typing `C-g'.  The dissociation output remains in the `*Dissociation*'
  1008. buffer for you to copy elsewhere if you wish.
  1009.  
  1010.    Dissociated Press operates by jumping at random from one point in the
  1011. buffer to another.  In order to produce plausible output rather than
  1012. gibberish, it insists on a certain amount of overlap between the end of
  1013. one run of consecutive words or characters and the start of the next.
  1014. That is, if it has just printed out `president' and then decides to jump
  1015. to a different point in the file, it might spot the `ent' in `pentagon'
  1016. and continue from there, producing `presidentagon'.(1)  Long sample
  1017. texts produce the best results.
  1018.  
  1019.    A positive argument to `M-x dissociated-press' tells it to operate
  1020. character by character, and specifies the number of overlap characters.
  1021. A negative argument tells it to operate word by word and specifies the
  1022. number of overlap words.  In this mode, whole words are treated as the
  1023. elements to be permuted, rather than characters.  No argument is
  1024. equivalent to an argument of two.  For your againformation, the output
  1025. goes only into the buffer `*Dissociation*'.  The buffer you start with
  1026. is not changed.
  1027.  
  1028.    Dissociated Press produces nearly the same results as a Markov chain
  1029. based on a frequency table constructed from the sample text.  It is,
  1030. however, an independent, ignoriginal invention.  Dissociated Press
  1031. techniquitously copies several consecutive characters from the sample
  1032. between random choices, whereas a Markov chain would choose randomly for
  1033. each word or character.  This makes for more plausible sounding results,
  1034. and runs faster.
  1035.  
  1036.    It is a mustatement that too much use of Dissociated Press can be a
  1037. developediment to your real work.  Sometimes to the point of outragedy.
  1038. And keep dissociwords out of your documentation, if you want it to be
  1039. well userenced and properbose.  Have fun.  Your buggestions are welcome.
  1040.  
  1041.    ---------- Footnotes ----------
  1042.  
  1043.    (1)  This dissociword actually appeared during the Vietnam War, when
  1044. it was very appropriate.
  1045.  
  1046. 
  1047. File: emacs,  Node: Amusements,  Next: Customization,  Prev: Dissociated Press,  Up: Top
  1048.  
  1049. Other Amusements
  1050. ================
  1051.  
  1052.    If you are a little bit bored, you can try `M-x hanoi'.  If you are
  1053. considerably bored, give it a numeric argument.  If you are very very
  1054. bored, try an argument of 9.  Sit back and watch.
  1055.  
  1056.    If you want a little more personal involvement, try `M-x gomoku',
  1057. which plays the game Go Moku with you.
  1058.  
  1059.    `M-x blackbox' and `M-x mpuz' are two kinds of puzzles.  `blackbox'
  1060. challenges you to determine the location of objects inside a box by
  1061. tomography.  `mpuz' displays a multiplication puzzle with letters
  1062. standing for digits in a code that you must guess--to guess a value,
  1063. type a letter and then the digit you think it stands for.
  1064.  
  1065.    `M-x dunnet' runs an adventure-style exploration game, which is a
  1066. bigger sort of puzzle.
  1067.  
  1068.    When you are frustrated, try the famous Eliza program.  Just do `M-x
  1069. doctor'.  End each input by typing `RET' twice.
  1070.  
  1071.    When you are feeling strange, type `M-x yow'.
  1072.  
  1073. 
  1074. File: emacs,  Node: Customization,  Next: Quitting,  Prev: Amusements,  Up: Top
  1075.  
  1076. Customization
  1077. *************
  1078.  
  1079.    This chapter talks about various topics relevant to adapting the
  1080. behavior of Emacs in minor ways.  See `The Emacs Lisp Reference Manual'
  1081. for how to make more far-reaching changes.
  1082.  
  1083.    All kinds of customization affect only the particular Emacs session
  1084. that you do them in.  They are completely lost when you kill the Emacs
  1085. session, and have no effect on other Emacs sessions you may run at the
  1086. same time or later.  The only way an Emacs session can affect anything
  1087. outside of it is by writing a file; in particular, the only way to make
  1088. a customization `permanent' is to put something in your `.emacs' file
  1089. or other appropriate file to do the customization in each session.
  1090. *Note Init File::.
  1091.  
  1092. * Menu:
  1093.  
  1094. * Minor Modes::           Each minor mode is one feature you can turn on
  1095.                  independently of any others.
  1096. * Variables::           Many Emacs commands examine Emacs variables
  1097.                  to decide what to do; by setting variables,
  1098.                  you can control their functioning.
  1099. * Keyboard Macros::       A keyboard macro records a sequence of
  1100.                  keystrokes to be replayed with a single
  1101.                  command.
  1102. * Key Bindings::       The keymaps say what command each key runs.
  1103.                  By changing them, you can "redefine keys".
  1104. * Keyboard Translations::  If your keyboard passes an undesired code
  1105.                  for a key, you can tell Emacs to
  1106.                  substitute another code.
  1107. * Syntax::           The syntax table controls how words and
  1108.                   expressions are parsed.
  1109. * Init File::           How to write common customizations in the
  1110.                              `.emacs' file.
  1111.  
  1112.